package com.woniuxy.book.mq;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
public class SubscribeComsumer {

    @RabbitListener(bindings = {
            @QueueBinding(exchange = @Exchange(name = "fanout", type = ExchangeTypes.FANOUT),
                    value = @Queue(name = "store.queue"))
    })
    @RabbitHandler
    public void comsumerStore(String message) {
        System.out.println("处理库存" + message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(exchange = @Exchange(name = "fanout", type = ExchangeTypes.FANOUT),
                    value = @Queue(name = "score.queue"))
    })
    @RabbitHandler
    public void comsumerScore(String message) {
        System.out.println("处理积分" + message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(exchange = @Exchange(name = "direct"),
                    value = @Queue(name = "d2.queue"),
                    key = "d2")
    })
    @RabbitHandler
    public void comsumerD2(String message) {
        System.out.println("处理奇数" + message);
    }

    @RabbitListener(bindings = {
            @QueueBinding(exchange = @Exchange(name = "direct"),
                    value = @Queue(name = "d1.queue"),
                    key = "d1")
    })
    @RabbitHandler
    public void comsumerD1(String message) {
        System.out.println("处理偶数" + message);
    }
}
